var avatarUp, avatarUp1, avatarUp2 = "";

function iconTypeChange() {
    avatarUp = new $IconUpload("avatar0");
    avatarUp.initIcon();
    avatarUp1 = new $IconUpload("avatar1");
    avatarUp1.initIcon();
    avatarUp2 = new $IconUpload("avatar2");
    avatarUp2.initIcon();
}

$(document).on('click', '.cp_img_delete0', function () {
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/delteCancel2",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $("#avatar0PreId").children().remove();
            $("#avatar0BtnId").css({'pointer-events': 'auto', 'cursor': 'pointer', 'background': 'white'});
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});

$(document).on('click', '.cp_img_delete1', function () {
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/delteCancel2",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $("#avatar1PreId").children().remove();
            $("#avatar1BtnId").css({'pointer-events': 'auto', 'cursor': 'pointer', 'background': 'white'});
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});

$(document).on('click', '.cp_img_delete2', function () {//删除上传打分照片
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/delteCancel2",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $("#avatar2PreId").children().remove();
            $("#avatar2BtnId").css({'pointer-events': 'auto', 'cursor': 'pointer', 'background': 'white'});
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});

function submissionUploadIcons() {
    var reservationsId = document.getElementById("reservationsId").value;
    var customerId = document.getElementById("customerId").value;
    var doctor = document.getElementById("doctor").value;
    var toothPosition = "";
    if (doctor == null || doctor == "") {
        alert("医生不能为空！");
        return;
    }
    var toothPositionA = document.getElementById("leftUp").innerHTML;
    var toothPositionB = document.getElementById("rightUp").innerHTML;
    var toothPositionC = document.getElementById("leftDown").innerHTML;
    var toothPositionD = document.getElementById("rightDown").innerHTML;
    if (toothPositionA.length <= 0 && toothPositionB.length <= 0 && toothPositionC.length <= 0 && toothPositionD.length <= 0) {
        Feng.error("牙位不能为空！");
        return false;
    }
    if (toothPositionA.length > 0) {
        toothPosition = "A" + toothPositionA;
    } else if (toothPositionB.length > 0) {
        toothPosition = "B" + toothPositionB;
    } else if (toothPositionC.length > 0) {
        toothPosition = "C" + toothPositionC;
    } else if (toothPositionD.length > 0) {
        toothPosition = "D" + toothPositionD;
    }
    var payServiceId = document.getElementById("payServiceId").value;
    if (payServiceId == null || payServiceId == "") {
        alert("项目不能为空！");
        return;
    }
    var remarks = document.getElementById("remarks").value;
    if (remarks === null || remarks === "") {
        alert("护士不能为空！");
        return;
    }
    if ($("#avatar0PreId").children().length != 1) {
        alert("术前只能上传一张照片");
        return;
    }
    if ($("#avatar1PreId").children().length != 1) {
        alert("术中只能上传一张照片");
        return;
    }
    if ($("#avatar2PreId").children().length != 1) {
        alert("术后只能上传一张照片");
        return;
    }
    var finnallyTime = document.getElementById("finnallyTime").value;
    var incoType = "术前,术中,术后";
    var cri = payServiceId + "," + customerId + "," + reservationsId + "," + remarks + "," + finnallyTime + "," + doctor + "," + toothPosition + "," + incoType;
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/submissionUploadIcons",
        type: "post",
        data: {"cri": cri},
        success: function (data) {
            if ('hint' == data) {
                alert('只能上传对应类型的一张照片，请删除多余的照片!');
            } else if ('ps' == data) {
                alert('请选择图片!');
            } else {
                Feng.success("提交成功!");
                window.parent.QualityAssurancesByone.table.refresh();
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            }
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
};

$(function () {
    iconTypeChange()
});